<style>
.app-main{
  background: #f5f9ff;
  .l{
    border-top: 1px solid #ebeef5;
    font-size: 15px;
    padding-top: 20px;
  }

  .a{
    width: 1600px;
    height: 1000px;
  }


}
</style>
<template>
  <div class="app-container" style="margin: auto; margin-top: 20px; border-radius:5px; width: 80%; height: 700px; background: #FFFFFF">
    <el-dialog title="操作" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" class="a">
      <p class="l">确认要将选中的应付单生成应付对账单吗？</p>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取消</el-button>
    <el-button type="primary" @click="bao">确认</el-button>
  </span>
    </el-dialog>

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-button type="primary" @click="tiao()" plain>结算</el-button>
      <el-button type="primary" plain @click="shen">生成对账单</el-button>
      <el-button plain>导入</el-button>
      <el-button plain @click="handleExport">导出</el-button>
      <el-button @click="handlePrint" plain>打印</el-button>
      <br><br>
      <el-form-item label="结算状态">
        <el-select v-model="queryParams.settlementStatus" placeholder="请选择" clearable>
          <el-option label="全部" value="全部"></el-option>
          <el-option label="未结算" value="未结算"></el-option>
          <el-option label="部分完成" value="部分完成"></el-option>
          <el-option label="结算完成" value="结算完成"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="始发地">
        <el-select v-model="queryParams.carrierType" placeholder="请选择" clearable>
          <el-option label="合同物流承运商" value="合同物流承运商"></el-option>
          <el-option label="专线物流承运商" value="专线物流承运商"></el-option>
          <el-option label="第三方物流承运商" value="第三方物流承运商"></el-option>
          <el-option label="临时供应商" value="临时供应商"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="目的地">
        <el-select v-model="queryParams.carrierType" placeholder="请选择" clearable>
          <el-option label="合同物流承运商" value="合同物流承运商"></el-option>
          <el-option label="专线物流承运商" value="专线物流承运商"></el-option>
          <el-option label="第三方物流承运商" value="第三方物流承运商"></el-option>
          <el-option label="临时供应商" value="临时供应商"></el-option>
        </el-select>
      </el-form-item>
      <br>
      <el-form-item label="签收时间">
        <el-date-picker
          v-model="daterangeSignTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['yfd:yfd:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['yfd:yfd:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['yfd:yfd:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['yfd:yfd:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="yfdList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="应付单号" align="center" prop="payableOrderNo" />
      <el-table-column label="运单号" align="center" prop="waybillNo" />
      <el-table-column label="承运商" align="center" prop="carrier" />
      <el-table-column label="订单状态" align="center" prop="orderStatus" >
        <template slot-scope="scope">
          <span>{{scope.row.orderStatus==0?'待审核':scope.row.orderStatus==1?'待调度':scope.row.orderStatus==2?'运输中':scope.row.orderStatus==3?'已签收':scope.row.orderStatus==4?'已拒绝':'已取消'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="签收时间" align="center" prop="signTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.signTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结算状态" align="center" prop="settlementStatus" >
        <template slot-scope="scope">
          <span>{{scope.row.settlementStatus==1?'已结算':'未结算'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="结算时间" align="center" prop="settlementTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.settlementTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="对账单状态" align="center" prop="reconciliationStatus">
        <template slot-scope="scope">
          <span>{{scope.row.reconciliationStatus==1?'已生成对账单':'未生成对账单'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="对账单号" align="center" prop="reconciliationNo" />
      <el-table-column label="成本合计(元)" align="center" prop="totalCost" />
      <el-table-column label="运费成本(元)" align="center" prop="transportationCost" />
      <el-table-column label="包装费(元)" align="center" prop="packagingFee" />
      <el-table-column label="装卸费(元)" align="center" prop="handlingFee" />
      <el-table-column label="其他费用(元)" align="center" prop="otherFees" />
      <el-table-column label="应付(元)" align="center" prop="payable" />
      <el-table-column label="现付(元)" align="center" prop="cashOnDelivery" />
      <el-table-column label="预付(元)" align="center" prop="prepaid" />
      <el-table-column label="到付(元)" align="center" prop="collectOnDelivery" />
      <el-table-column label="周期付(元)" align="center" prop="periodicPayment" />
      <el-table-column label="已对账金额(元)" align="center" prop="reconciledAmount" />
      <el-table-column label="未对账金额(元)" align="center" prop="unreconciledAmount" />
      <el-table-column label="扣款金额(元)" align="center" prop="deductionAmount" />
      <el-table-column label="实付(元)" align="center" prop="actualPayment" />
      <el-table-column label="发货时间" align="center" prop="shippingTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.shippingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="始发地" align="center" prop="origin" />
      <el-table-column label="目的地" align="center" prop="destination" />
      <el-table-column label="司机" align="center" prop="driver" />
      <el-table-column label="手机号码" align="center" prop="phoneNumber" />
      <el-table-column label="创建人" align="center" prop="createdBy" />
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['yfd:yfd:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['yfd:yfd:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    <!-- 添加或修改应付单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="应付单号" prop="payableOrderNo">
          <el-input v-model="form.payableOrderNo" placeholder="请输入应付单号" />
        </el-form-item>
        <el-form-item label="运单号" prop="waybillNo">
          <el-input v-model="form.waybillNo" placeholder="请输入运单号" />
        </el-form-item>
        <el-form-item label="承运商" prop="carrier">
          <el-input v-model="form.carrier" placeholder="请输入承运商" />
        </el-form-item>
        <el-form-item label="签收时间" prop="signTime">
          <el-date-picker clearable
            v-model="form.signTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择签收时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结算时间" prop="settlementTime">
          <el-date-picker clearable
            v-model="form.settlementTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择结算时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="对账单号" prop="reconciliationNo">
          <el-input v-model="form.reconciliationNo" placeholder="请输入对账单号" />
        </el-form-item>
        <el-form-item label="成本合计(元)" prop="totalCost">
          <el-input v-model="form.totalCost" placeholder="请输入成本合计(元)" />
        </el-form-item>
        <el-form-item label="运费成本(元)" prop="transportationCost">
          <el-input v-model="form.transportationCost" placeholder="请输入运费成本(元)" />
        </el-form-item>
        <el-form-item label="包装费(元)" prop="packagingFee">
          <el-input v-model="form.packagingFee" placeholder="请输入包装费(元)" />
        </el-form-item>
        <el-form-item label="装卸费(元)" prop="handlingFee">
          <el-input v-model="form.handlingFee" placeholder="请输入装卸费(元)" />
        </el-form-item>
        <el-form-item label="其他费用(元)" prop="otherFees">
          <el-input v-model="form.otherFees" placeholder="请输入其他费用(元)" />
        </el-form-item>
        <el-form-item label="应付(元)" prop="payable">
          <el-input v-model="form.payable" placeholder="请输入应付(元)" />
        </el-form-item>
        <el-form-item label="现付(元)" prop="cashOnDelivery">
          <el-input v-model="form.cashOnDelivery" placeholder="请输入现付(元)" />
        </el-form-item>
        <el-form-item label="预付(元)" prop="prepaid">
          <el-input v-model="form.prepaid" placeholder="请输入预付(元)" />
        </el-form-item>
        <el-form-item label="到付(元)" prop="collectOnDelivery">
          <el-input v-model="form.collectOnDelivery" placeholder="请输入到付(元)" />
        </el-form-item>
        <el-form-item label="周期付(元)" prop="periodicPayment">
          <el-input v-model="form.periodicPayment" placeholder="请输入周期付(元)" />
        </el-form-item>
        <el-form-item label="已对账金额(元)" prop="reconciledAmount">
          <el-input v-model="form.reconciledAmount" placeholder="请输入已对账金额(元)" />
        </el-form-item>
        <el-form-item label="未对账金额(元)" prop="unreconciledAmount">
          <el-input v-model="form.unreconciledAmount" placeholder="请输入未对账金额(元)" />
        </el-form-item>
        <el-form-item label="扣款金额(元)" prop="deductionAmount">
          <el-input v-model="form.deductionAmount" placeholder="请输入扣款金额(元)" />
        </el-form-item>
        <el-form-item label="实付(元)" prop="actualPayment">
          <el-input v-model="form.actualPayment" placeholder="请输入实付(元)" />
        </el-form-item>
        <el-form-item label="发货时间" prop="shippingTime">
          <el-date-picker clearable
            v-model="form.shippingTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发货时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="司机" prop="driver">
          <el-input v-model="form.driver" placeholder="请输入司机" />
        </el-form-item>
        <el-form-item label="手机号码" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable
            v-model="form.createdTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listYfd, getYfd, delYfd, addYfd, updateYfd } from "@/api/yfd/yfd";

export default {
  name: "Yfd",
  data() {
    return {
      dialogVisible:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 应付单表格数据
      yfdList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 创建时间时间范围
      daterangeSignTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        signTime: null,
        settlementStatus: null,
        origin: null,
        destination: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询应付单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeSignTime && '' != this.daterangeSignTime) {
        this.queryParams.params["beginSignTime"] = this.daterangeSignTime[0];
        this.queryParams.params["endSignTime"] = this.daterangeSignTime[1];
      }
      listYfd(this.queryParams).then(response => {
        this.yfdList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        payableOrderNo: null,
        waybillNo: null,
        carrier: null,
        orderStatus: null,
        signTime: null,
        settlementStatus: null,
        settlementTime: null,
        reconciliationStatus: null,
        reconciliationNo: null,
        totalCost: null,
        transportationCost: null,
        packagingFee: null,
        handlingFee: null,
        otherFees: null,
        payable: null,
        cashOnDelivery: null,
        prepaid: null,
        collectOnDelivery: null,
        periodicPayment: null,
        reconciledAmount: null,
        unreconciledAmount: null,
        deductionAmount: null,
        actualPayment: null,
        shippingTime: null,
        origin: null,
        destination: null,
        driver: null,
        phoneNumber: null,
        createdBy: null,
        createdTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeSignTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加应付单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getYfd(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改应付单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateYfd(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addYfd(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除应付单编号为"' + ids + '"的数据项？').then(function() {
        return delYfd(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('yfd/yfd/export', {
        ...this.queryParams
      }, `yfd_${new Date().getTime()}.xlsx`)
    },
    tiao(){
      if(this.ids.length==0){
        this.$message.error("请选着一条应收单");
      }else{
        if(this.ids.length>1){
          this.$message.error("选择一条数据")
        }else{
          this.$router.push({path:'/jiesuan1',query:{ids:this.ids}})
        }
      }
    },
    shen(){
      if(this.ids.length==0){
        this.$message.error("请选着一条应收单");
      }else{
        this.dialogVisible = true;
        const id=this.ids;
        getYfd(id).then(response => {
          this.form = response.data
        });

      }
    },
    handlePrint() {
      // 调用 window.print() 方法进行打印
      window.print();
    },
    bao(){
      this.$router.push({path:'/jiesuan1',query:{ids:this.ids}})
    }
  }
};
</script>
